﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Configuration;
using System.IO;
using System.Security.AccessControl;
using RioStudio.Website.Model;

namespace RioStudio.Website.View.Admin.SEO
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    var setting = tData.Instance.ExecuteReader<Setting>("Proc_GetAllSetting");

                    txtWebsiteTitle.Text = setting.FirstOrDefault(i => i.SettingKey == "title").SettingValue;
                    txtKeyword.Text = setting.FirstOrDefault(i => i.SettingKey == "keyword").SettingValue;
                    txtDescription.Text = setting.FirstOrDefault(i => i.SettingKey == "description").SettingValue;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                tData.Instance.ExecuteNonQuery("Proc_UpdateSetting", "keyword", txtKeyword.Text);
                tData.Instance.ExecuteNonQuery("Proc_UpdateSetting", "description", txtDescription.Text);
                tData.Instance.ExecuteNonQuery("Proc_UpdateSetting", "title", txtWebsiteTitle.Text);

                ScriptManager.RegisterStartupScript(this, this.GetType(), "SaveSuccessAlert", "alert('Cập nhật thành công')", true);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                Response.Redirect("~/Home");
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}